/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package de.hsmannheim.pepa.patientenportal.apanwep.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import de.hsmannheim.pepa.patientenportal.apanwep.service.ClpSerializer;
import de.hsmannheim.pepa.patientenportal.apanwep.service.messages_mobjectsLocalServiceUtil;
import de.hsmannheim.pepa.patientenportal.apanwep.service.persistence.messages_mobjectsPK;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Cedric Nana
 */
public class messages_mobjectsClp extends BaseModelImpl<messages_mobjects>
	implements messages_mobjects {
	public messages_mobjectsClp() {
	}

	@Override
	public Class<?> getModelClass() {
		return messages_mobjects.class;
	}

	@Override
	public String getModelClassName() {
		return messages_mobjects.class.getName();
	}

	@Override
	public messages_mobjectsPK getPrimaryKey() {
		return new messages_mobjectsPK(_messages_ID, _messageobjects_id);
	}

	@Override
	public void setPrimaryKey(messages_mobjectsPK primaryKey) {
		setMessages_ID(primaryKey.messages_ID);
		setMessageobjects_id(primaryKey.messageobjects_id);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return new messages_mobjectsPK(_messages_ID, _messageobjects_id);
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey((messages_mobjectsPK)primaryKeyObj);
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("messages_ID", getMessages_ID());
		attributes.put("messageobjects_id", getMessageobjects_id());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long messages_ID = (Long)attributes.get("messages_ID");

		if (messages_ID != null) {
			setMessages_ID(messages_ID);
		}

		Long messageobjects_id = (Long)attributes.get("messageobjects_id");

		if (messageobjects_id != null) {
			setMessageobjects_id(messageobjects_id);
		}
	}

	@Override
	public long getMessages_ID() {
		return _messages_ID;
	}

	@Override
	public void setMessages_ID(long messages_ID) {
		_messages_ID = messages_ID;

		if (_messages_mobjectsRemoteModel != null) {
			try {
				Class<?> clazz = _messages_mobjectsRemoteModel.getClass();

				Method method = clazz.getMethod("setMessages_ID", long.class);

				method.invoke(_messages_mobjectsRemoteModel, messages_ID);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getMessageobjects_id() {
		return _messageobjects_id;
	}

	@Override
	public void setMessageobjects_id(long messageobjects_id) {
		_messageobjects_id = messageobjects_id;

		if (_messages_mobjectsRemoteModel != null) {
			try {
				Class<?> clazz = _messages_mobjectsRemoteModel.getClass();

				Method method = clazz.getMethod("setMessageobjects_id",
						long.class);

				method.invoke(_messages_mobjectsRemoteModel, messageobjects_id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getmessages_mobjectsRemoteModel() {
		return _messages_mobjectsRemoteModel;
	}

	public void setmessages_mobjectsRemoteModel(
		BaseModel<?> messages_mobjectsRemoteModel) {
		_messages_mobjectsRemoteModel = messages_mobjectsRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _messages_mobjectsRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_messages_mobjectsRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	@Override
	public void persist() throws SystemException {
		if (this.isNew()) {
			messages_mobjectsLocalServiceUtil.addmessages_mobjects(this);
		}
		else {
			messages_mobjectsLocalServiceUtil.updatemessages_mobjects(this);
		}
	}

	@Override
	public messages_mobjects toEscapedModel() {
		return (messages_mobjects)ProxyUtil.newProxyInstance(messages_mobjects.class.getClassLoader(),
			new Class[] { messages_mobjects.class },
			new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		messages_mobjectsClp clone = new messages_mobjectsClp();

		clone.setMessages_ID(getMessages_ID());
		clone.setMessageobjects_id(getMessageobjects_id());

		return clone;
	}

	@Override
	public int compareTo(messages_mobjects messages_mobjects) {
		messages_mobjectsPK primaryKey = messages_mobjects.getPrimaryKey();

		return getPrimaryKey().compareTo(primaryKey);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof messages_mobjectsClp)) {
			return false;
		}

		messages_mobjectsClp messages_mobjects = (messages_mobjectsClp)obj;

		messages_mobjectsPK primaryKey = messages_mobjects.getPrimaryKey();

		if (getPrimaryKey().equals(primaryKey)) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return getPrimaryKey().hashCode();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(5);

		sb.append("{messages_ID=");
		sb.append(getMessages_ID());
		sb.append(", messageobjects_id=");
		sb.append(getMessageobjects_id());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(10);

		sb.append("<model><model-name>");
		sb.append(
			"de.hsmannheim.pepa.patientenportal.apanwep.model.messages_mobjects");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>messages_ID</column-name><column-value><![CDATA[");
		sb.append(getMessages_ID());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>messageobjects_id</column-name><column-value><![CDATA[");
		sb.append(getMessageobjects_id());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _messages_ID;
	private long _messageobjects_id;
	private BaseModel<?> _messages_mobjectsRemoteModel;
}